<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>入场记录</title>
    <script src="js/flexible.js"></script>
    <link rel="stylesheet" href="css/flexible.css">
    <link rel="stylesheet" href="css/reset.css">
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/vant.css">
    <script src="js/vue/vue.js"></script>
    <script src="js/vue/axios.js"></script>
    <script src="js/vue/MD5.js"></script>
    <script src="js/vue/vant.js"></script>
</head>
<body>
<div id="app">
    <template>
        <div class="nextTime">
            <span @click="beforeMonth">上一月</span>
            <span>{{from.date}}</span>
            <span @click="nextMonth">下一月</span>
        </div>
        <div v-if="dateList.length>0">
            <div class="sign_record_list" v-for="item in dateList">
                    <div class="sign_r_top">
                        {{item.Cardname}}
                    </div>
                    <div class="sign_r_bottom">
                        <div class="l">
                            <div class="tb">
                                <div class="name">签入时间</div>
                                <div class="value">{{item.SignIn_datatime}}</div>
                                <div class="clear"></div>
                            </div>
                
                            <div class="tb">
                                <div class="name">入场消费</div>
                                <div class="value">{{item.Charge}}</div>
                                <div class="clear"></div>
                            </div>
                
                            <div class="tb">
                                <div class="name">更衣柜</div>
                                <div class="value">{{item.Wardrobe}}</div>
                                <div class="clear"></div>
                            </div>
                
                        </div>
                        <div class="r">
                            <div v-if="item.Sign_type=='0'" class="sign_record_btn">未签出</div>
                            <div v-else class="sign_record_btn">已签出</div>
                        </div>
                        <div class="clear"></div>
                    </div>
            </div>
        </div>
        <!-- <div class="notDate" v-else>
            <img src="images/notDate.jpg"/>
        </div> -->
        <van-list
            v-model="loading"
            :finished="finished"
            finished-text="没有数据了"
            @load="getCardList"
        >
        <van-cell
            v-for="item in lists"
            :key="item"
            :title="item"
        />
        </van-list>
    </template>
</div>
</body>
<script>
var app = new Vue({
    el: '#app',
    data: {
        dateList:[],
        from:{
            date:'',
            page:'1',
        },
        month:'',
        year:'',
        date:'',
        lists: [],
        loading: false,
        finished: false,
        totalnum:'',
        totalpage:'',
        listd:[]
    },
    created(){
        //this.getCardList()
        this.addDate()
    },
    methods: {
        addDate() {
            nowDate = new Date();
            this.year=nowDate.getFullYear()
            this.month=nowDate.getMonth() + 1
            this.date=nowDate.getDate()
            let monthS=''
            if(this.month<10){
                monthS="0"+this.month
            }else{
                monthS=this.month
            }
            let dates=''
            if(this.date<10){
                dates="0"+this.date
            }else{
                dates=this.date
            }
                this.from.date = this.year + '-' + monthS + '-' + dates
        },
        beforeMonth(){
            this.month--
            if(this.month==0){
                this.year--
                this.month=12
            }
            let monthS=''
            if(this.month<10){
                monthS="0"+this.month
            }else{
                monthS=this.month
            }
            let dates=''
            if(this.date<10){
                dates="0"+this.date
            }else{
                dates=this.date
            }
            this.from.date = this.year + '-' + monthS + '-' + dates
            this.from.page='1'
			 this.dateList=[]
            this.lists=[]
            this.listd=[]
            this.getCardList()
        },
        nextMonth(){
            if(this.month==12){
                this.year++
                this.month=1
            }else{
                this.month++
            }
            let monthS=''
            if(this.month<10){
                monthS="0"+this.month
            }else{
                monthS=this.month
            }
            let dates=''
            if(this.date<10){
                dates="0"+this.date
            }else{
                dates=this.date
            }
            this.from.date = this.year + '-' + monthS + '-' + dates
            this.from.page='1'
			 this.dateList=[]
            this.lists=[]
            this.listd=[]
            this.getCardList()
        },
        // getCardList(){
        //     getVs()
        //     const params=this.from
        //     axios.get('/mobileapi/member/user_info.php?act=sign_record',{params:params}).then(data =>{
        //         console.log(data.data)
        //         let { msg, code,user} = data.data
        //             if (code !== 200) {
        //                 _this.$message({
        //                     message: msg,
        //                     type: 'error'
        //                 });
        //             } else {
        //                 data=data.data
        //                 this.dateList=data.data
        //                 console.log(this.dateList)
        //                 for(let i in this.dateList){
        //                     if(this.dateList[i].Wardrobe==''||this.dateList[i].Wardrobe==null){
        //                         this.dateList[i].Wardrobe="无"
        //                     }
        //                 }
        //             }
        //         }).catch(function (error) { 
        //             console.log(error); 
        //     });
        // },
        getCardList() {
            setTimeout(() => {
            // 异步更新数据
            getVs()
            const params=this.from
            axios.get('/mobileapi/member/user_info.php?act=sign_record',{params:params}).then(data =>{
                    console.log(data.data)
                    let { msg, code,user} = data.data
                        if (code !== 200) {
                            _this.$message({
                                message: msg,
                                type: 'error'
                            });
                        } else {
                            data=data.data
                            this.listd=data.data.list
                            if(this.listd.length>0||this.dateList.length>0){
                                this.totalnum=data.data.totalnum
                                this.from.page=parseInt(data.data.page)+1
                                for (let i = 0; i < this.listd.length; i++) {
                                    this.dateList.push(this.listd[i])
                                }
                                for(let i in this.dateList){
                                    if(this.dateList[i].Wardrobe==''||this.dateList[i].Wardrobe==null){
                                        this.dateList[i].Wardrobe="无"
                                    }
                                }    
                                this.loading = false
                                // 数据全部加载完成
                                if (this.dateList.length >= this.totalnum) {
                                    this.finished = true
                                }
                            }else{
                                this.loading = false
                                this.finished = true
                            }
                        }
                    }).catch(function (error) {
                        console.log(error); 
                })
            }, 500)
        },
    }  
})    
</script>
</html>